package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 巡查文件分类枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum PatrolFileCategory implements BaseEnum {
    PHOTO("PHOTO", "照片"),
    VIDEO("VIDEO", "视频"),
    AUDIO("AUDIO", "音频"),
    DOCUMENT("DOCUMENT", "文档"),
    SPREADSHEET("SPREADSHEET", "电子表格"),
    PRESENTATION("PRESENTATION", "演示文稿"),
    ARCHIVE("ARCHIVE", "压缩包"),
    OTHER("OTHER", "其他");

    private final String code;
    private final String description;

    PatrolFileCategory(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static PatrolFileCategory fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Patrol file category code cannot be null or empty");
        }

        for (PatrolFileCategory category : values()) {
            if (category.getCode().equals(code)) {
                return category;
            }
        }
        throw new IllegalArgumentException("Unknown patrol file category code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 枚举值，如果未找到返回null
     */
    public static PatrolFileCategory fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (PatrolFileCategory category : values()) {
            if (category.getDescription().equals(description)) {
                return category;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}